package ctbu.edu.cn.teachersjpa.webapi;

import ctbu.edu.cn.teachersjpa.domain.Teachers;
import ctbu.edu.cn.teachersjpa.respository.TeachersRepository;
import ctbu.edu.cn.teachersjpa.service.TeachersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/webapi/teachers")
public class teachersRestController {
    @Autowired
    private TeachersService teachersService;
    @GetMapping("/list")
    public List<Teachers> getAll() {
        List<Teachers> teachers = teachersService.findAll();
        return teachers;
    }

    /**
     *新增学生的方法/webapi/teachers/update
     * @param teacher
     * @return
     */
    @PostMapping("/insert")
    public Teachers insert(Teachers teacher){
        System.out.println(teacher);
        Teachers teachers1=teachersService.insert(teacher);
        return teachers1;
    }

    /**
     * 更新学生的方法/webapi/teachers/update
     * @param teachers
     * @return
     */
    @PutMapping("/update")
    public Teachers update(Teachers teachers){
        Teachers teachers1=teachersService.update(teachers);
        return teachers1;
    }

    /**
     * 删除学生的方法/webapi/teachers/delete
     * @param
     * @return
     */
    @DeleteMapping("/delete{id}")
    public void delete(@PathVariable Integer id){
        teachersService.delete(id);
    }

    @DeleteMapping("delete")
    public void delete1( Integer id){
        teachersService.delete(id);
    }

    @GetMapping("/get/{id}")
    public Teachers get(@PathVariable Integer id){
        Teachers teachers=teachersService.findById(id);
        return teachers;
    }
}

